﻿using System.Collections.ObjectModel;
using Core.Event;
using Game.Trade;

namespace Game {
    /// <summary>
    /// 玩家交易模块
    /// </summary>
    public class PlayerTradeModule : PlayerModule , IBuyer,ISeller {
        public int Money {
            get;
            protected set;
        }
        
        public ReadOnlyCollection<ISellable> SellList {
            get => null;
        }

        public PlayerTradeModule(Player player) : base(player) {
            Money = 99999;
        }
        
        public void Buy(ISellable thing) {
            if (thing is Weapon weapon) {
                //武器
                mPlayer.BagModule.WeaponBag.AddWeapon(weapon);
                var display = WeaponFactory.SpawnView(weapon, mPlayer.Component.WeaponBag);
                weapon.AttachInstance(display);
            }else if (thing is WeaponEffect weaponEffect) {
                //武器效果
                mPlayer.BagModule.WeaponEffectBag.AddEffect(weaponEffect.Data.ID);
            }

            Money -= thing.Cost;
            GameEventMgr.Ins.PushEvent(GameEventID.CoinValueChanged);    
        }

        public void Sell(ISellable thing) {
            //获取收益
            Money += thing.Revenue;
            if (thing is Weapon weapon) {
                mPlayer.BagModule.WeaponBag.RemoveWeapon(weapon);
            }
        }
    }
}